<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.ok{
			    color:green;
			}
			.error{
			    color:red;
			}
		</style>
	</head>
	<body>
		名字：<input type="text" id="name" onblur="checkName()"/>
		<span id="nameMsg">5-10位字母、数字、下划线</span>
		<br/>
		邮箱：<input type="text" id="email" onblur="checkEmail()"/>
		<span id="emailMsg">必须符合邮箱的格式</span>
		
		<script type="text/javascript">
			function checkName() {
				console.log("checkName")
				var name = document.getElementById("name").value;
				var span = document.getElementById("nameMsg");
				var reg = /^[a-zA-Z0-9_]{5,9}$/;
				
				if(name.match(reg)) {
					/* class="ok" */
					span.className = "ok";
				} else {
					span.className = "error";
				}
			}
			
			function checkEmail() {
				console.log("checkEmail")
				var name = document.getElementById("email").value;
				var span = document.getElementById("emailMsg");
				// situ@qq.com
				var reg = /^[a-zA-Z0-8_]{3,5}@[a-zA-Z0-8_]+\.[a-zA-Z0-8_]+$/;
				
				if(name.match(reg)) {
					/* class="ok" */
					span.className = "ok";
				} else {
					span.className = "error";
				}
			}
		</script>
	</body>
</html>
